﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using ElementumForever.Interfaces;

namespace ElementumForever.Editer
{
    class ItemMenuScene : BaseScene, IMouseControl
    {
        Dictionary<string, ItemGroupScene> _selectScenes;
        ItemGroupScene currentGroup;
        MainFormModel _formModel;

        public ItemMenuScene(MainGame game, MainFormModel _formModel)
            : base(game)
        {
            this._formModel = _formModel;
            Initialize(game);
            OnCreat();
        }

        protected override void Initialize(MainGame game)
        {
            base.Initialize(game);
            Name = "ItemScene";
            Width = 700;
            Height = 450;
            Center = new Vector2(400, 240);
            OriginX = Width / 2;
            OriginY = Height / 2;
            Color = Color.LightGray;
            Alpha = 0.5f;
        }

        public override void OnCreat()
        {
            base.OnCreat();
            _selectScenes = new Dictionary<string, ItemGroupScene>();
            ItemGroupScene group_1;
            group_1 = new ItemGroupScene(this);
            group_1.OnCreat();
            currentGroup = group_1;
            //AttachChild(group);
            //se.Center = new Vector2(200, 240);
            group_1.OnAttach(this);
            //_selectScenes.Add("s01",se);
        }

        public void SelectItem(BaseEntity entity) {
            if (entity != null)
            {
                //Console.WriteLine(entity.Name);
                _formModel.OnSelectEntity(entity);
            }
            else
            {
                //Console.WriteLine("null");
            }
        }

        public void SetState(string state)
        {
            if (_selectScenes.ContainsKey(state))
                currentGroup = _selectScenes[state];
        }

        public override void OnDraw(GameTime gameTime, Microsoft.Xna.Framework.Graphics.SpriteBatch spriteBatch)
        {
            if (Visiable)
            {
                base.OnDraw(gameTime, spriteBatch);
                if (currentGroup != null)
                    currentGroup.OnDraw(gameTime, spriteBatch);
            }
        }

        public override void OnUpdate(GameTime gameTime)
        {
            if (Visiable)
            {
                base.OnUpdate(gameTime);
                if (currentGroup != null)
                    currentGroup.OnUpdate(gameTime);
            }
        }

        public void OnMouseClick(Microsoft.Xna.Framework.Input.MouseState state)
        {
            if (Visiable)
            {
                currentGroup.OnMouseClick(state);
            }
        }

        public void OnMouseDown(Microsoft.Xna.Framework.Input.MouseState state)
        {
            if (Visiable)
            { currentGroup.OnMouseDown(state); }
        }

        public void OnMouseUp(Microsoft.Xna.Framework.Input.MouseState state)
        {
            if (Visiable)
            { currentGroup.OnMouseUp(state); }
        }

        public void OnMouseMove(Microsoft.Xna.Framework.Input.MouseState state)
        {
            if (Visiable)
            { currentGroup.OnMouseMove(state); }
        }
    }
}
